package cn.wsalix.admin.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import cn.anlaser.entity.ParentEntity;
import cn.wsalix.admin.status.MenuEnum;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "ADMIN_MENU")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DynamicUpdate
@DynamicInsert
@Data
@EqualsAndHashCode(callSuper = false, exclude = { "roles" })
@ToString(exclude = { "roles" })
@DiscriminatorColumn(name = "menu_type", discriminatorType = DiscriminatorType.STRING, length = 15)
@DiscriminatorValue("ADMIN_MENU")
public class SysMenu extends ParentEntity<SysMenu> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7419476228273541892L;

	public SysMenu() {
		super();
	}

	public SysMenu(String code, String name) {
		this.code = code;
		this.name = name;
	}

	public SysMenu(String code, String name, String menuUrl) {
		this.code = code;
		this.name = name;
		this.menuUrl = menuUrl;
	}

	@Column(name = "NAME")
	private String name;
	@Column(name = "CODE")
	protected String code;

	private String menuUrl;
	private String pattern;
	private boolean display;
	private MenuEnum status;
	@Transient
	private String selected;
	@ManyToMany(mappedBy = "menus")
	private List<SysRole> roles;
	@JsonIgnore
	@Transient
	private List<SysMenu> childs;
}
